package xyz.xmh.pojo.request.file;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Data;
import xyz.xmh.autoconfigure.TokenStatic;
import xyz.xmh.pojo.enums.CategoryEnum;
import xyz.xmh.pojo.enums.OrderByEnum;
import xyz.xmh.pojo.enums.OrderDirectionEnum;

/**
 * 搜索文件请求参数
 *
 * @author xuMingHai
 */
@Data
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SearchRequest {

    private String driveId = TokenStatic.DEFAULT_DRIVE_ID;
    private int limit = 100;
    private String query = "name match \"\"";
    private String imageThumbnailProcess = "image/resize,w200/format,jpeg";
    private String imageUrlProcess = "image/resize,w1920/format,jpeg";
    private String videoThumbnailProcess = "video/snapshot,t0,fJpg,arAuto,w300";
    private String orderBy = OrderByEnum.UPDATE_AT.getValue() + " " + OrderDirectionEnum.DESC.getValue();

    /**
     * 设置要搜索的文件名，不指定文件类型
     *
     * @param query 文件名
     */
    public void setQuery(String query) {
        this.query = "name match \"" + query + "\"";
    }

    /**
     * 设置要搜索的文件名，指定文件类型
     *
     * @param query        文件名
     * @param categoryEnum 文件类型
     */
    public void setQuery(String query, CategoryEnum categoryEnum) {
        this.query = "name match \"" + query + "\"" + categoryEnum.getValue();
    }

    /**
     * 设置排序方式
     *
     * @param orderBy       根据什么排序
     * @param directionEnum 排序方向
     */
    public void setOrderBy(OrderByEnum orderBy, OrderDirectionEnum directionEnum) {
        this.orderBy = orderBy.getValue() + " " + directionEnum.getValue();
    }
}
